package com.yonyou.rabbitmq.config;

import com.yonyou.rabbitmq.producer.MessageProcess;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class DefaultStrategyConfig {

    @Bean
    @ConditionalOnMissingBean(MessageProcess.class)
    public MessageProcess defaultStrategy() {
        return new MessageProcess.Builder()
                .preSend(messageInfo -> log.info("第一次发送前..{}",messageInfo))

                .messageAck(messageInfo -> log.info("消息投递成功..{}",messageInfo))

                .messageNack(messageInfo -> log.info("消息投递失败{}",messageInfo))

                .pickResendMessages(() -> {
                    log.info("定时任务: 查找需要重发的消息..");
                    return null;
                })

                .preResend(id -> log.info("消息重发前..{}",id))

                .messageRouteFail((messageProperties, messageBody, exchange, routingKey) ->
                        log.info("路由失败的消息messageBody:{},messageProperties:{}",messageBody,messageProperties))

                .build();
    }

}
